﻿#include<iostream>
#include"hstring.h"



int main() {
	hstring str{ "123abc" };
	str = str + -123456 + 123534;
	std::cout << str;
}

//数字转字符串
 /*
//第一种，两个循环
unsigned int val = -1;
char str[12]{};
char strR[12]{};
int len{};
bool bfs = val < 0;
if (bfs)val = -1 * val;
do {
	str[len++] = val % 10 + 48;
	val = val / 10;
} while (val);
if (bfs)str[len++] = '-';
for (int i = 0; str[i]; i++) {
	strR[i] = str[len - i - 1];
}
std::cout << strR;

//第二种，一个循环
int val = -1;
char str[12]{};
int len{ 11 };
bool bfs = val < 0;
if (bfs)val = -1 * val;
do {
	str[--len] = val % 10 + 48;
	val = val / 10;
} while (val);
if (bfs)str[--len] = '-';
std::cout << &str[len];

//第三种，去掉if，精简代码
int val = 0;
char str[12]{};
int len{ 11 };
bool bzs = (val >= 0);
val = val * (bzs * 2 - 1);//bzs只有2个结果，一个1，一个0，0-1=-1，1-1=0，所以乘2，0*2-1=-1，1*2-1=1
do {
	str[--len] = val % 10 + 48;
} while (val = val / 10);
//推导过程
//	0|len-(1-bzs)
//	1|len-(1-bzs)
//	0|'-'*(bzs+1)*(1-bzs) + str[len] * bzs
//	1|'-'*(bzs+1)*(1-bzs) + str[len] * bzs
str[len = len - (1 - bzs)] = '-' * (bzs + 1) * (1 - bzs) + str[len] * bzs;
std::cout << &str[len];
*/